source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-010.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 1065343 objects.
Mean distance to the closest unit in the map: 1.193.
plot(model, type="changes")
df <- mpr.load_data("datos_dia_2k.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:1065343 Length:1065343 Min. : 1.0 Min. :-196.0
Class :character Class :character 1st Qu.: 91.0 1st Qu.: 144.0
Mode :character Mode :character Median :183.0 Median : 201.0
Mean :182.8 Mean : 201.5
3rd Qu.:274.0 3rd Qu.: 263.0
Max. :366.0 Max. : 469.0
tmin precip nevada prof_nieve
Min. :-252.00 Min. : 0.00 Min. :0 Min. : 0.0000
1st Qu.: 47.00 1st Qu.: 0.00 1st Qu.:0 1st Qu.: 0.0000
Median : 100.00 Median : 0.00 Median :0 Median : 0.0000
Mean : 97.54 Mean : 17.05 Mean :0 Mean : 0.6185
3rd Qu.: 153.00 3rd Qu.: 2.00 3rd Qu.:0 3rd Qu.: 0.0000
Max. : 332.00 Max. :3361.00 Max. :0 Max. :1240.0000
longitud latitud altitud
Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.:39.47 1st Qu.: -4.850 1st Qu.: 47
Median :41.29 Median : -1.411 Median : 287
Mean :40.10 Mean : -2.391 Mean : 486
3rd Qu.:42.22 3rd Qu.: 1.296 3rd Qu.: 691
Max. :43.57 Max. : 4.216 Max. :2535
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13
7724 61066 71660 46008 22211 56906 45197 39247 52210 15126 25347 46495 55161
14 15 16 17 18 19 20 21 22 23 24 25
9567 1463 51356 59631 58281 42821 30202 93369 47194 27491 51200 48410
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "tmax", "tmin", "precip", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt tmax tmin precip longitud latitud
[1,] 0.01605063 -0.8290019 -0.8768082 0.293938370 0.5649890 0.4146627
[2,] 0.77455275 0.3849234 0.3626317 -0.001570071 0.1797045 0.1932196
altitud
[1,] 0.46180241
[2,] -0.01398282
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud latitud altitud tmax precip tmin fecha_cnt
0.9517478 0.9247384 0.9158391 0.9074087 0.9018573 0.8971768 0.8915602
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-32 Min. :-75.0 Min. : 0.000 Min. :0
1st Qu.: 90.0 1st Qu.:208 1st Qu.:145.0 1st Qu.: 0.000 1st Qu.:0
Median :179.0 Median :234 Median :172.0 Median : 0.000 Median :0
Mean :180.8 Mean :229 Mean :164.4 Mean : 4.615 Mean :0
3rd Qu.:272.0 3rd Qu.:262 3rd Qu.:201.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :429 Max. :322.0 Max. :361.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.38 Mean :-16.06 Mean : 384.6
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.0 Min. :-252.00 Min. : 0.00
1st Qu.: 92.0 1st Qu.: 142.0 1st Qu.: 44.00 1st Qu.: 0.00
Median :183.0 Median : 197.0 Median : 94.00 Median : 0.00
Mean :182.8 Mean : 199.8 Mean : 93.23 Mean : 16.62
3rd Qu.:274.0 3rd Qu.: 263.0 3rd Qu.: 146.00 3rd Qu.: 2.00
Max. :366.0 Max. : 469.0 Max. : 332.00 Max. :633.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.95 1st Qu.: -4.010
Median :0 Median : 0.0000 Median :41.39 Median : -1.117
Mean :0 Mean : 0.6556 Mean :40.86 Mean : -1.509
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 1.366
Max. :0 Max. :1240.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 59.0
Median : 336.0
Mean : 492.4
3rd Qu.: 704.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :-63.0 Min. :-133.00 Min. : 622.0 Min. :0
1st Qu.:110.0 1st Qu.:106.0 1st Qu.: 55.00 1st Qu.: 683.0 1st Qu.:0
Median :272.0 Median :148.0 Median : 102.00 Median : 776.0 Median :0
Mean :219.1 Mean :146.1 Mean : 92.28 Mean : 859.2 Mean :0
3rd Qu.:306.5 3rd Qu.:195.0 3rd Qu.: 138.00 3rd Qu.: 934.5 3rd Qu.:0
Max. :362.0 Max. :332.0 Max. : 240.00 Max. :3361.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -1.9623 1st Qu.: 44.0
Median : 0.000 Median :41.57 Median : 0.8856 Median : 247.0
Mean : 2.595 Mean :40.75 Mean : -0.7467 Mean : 587.5
3rd Qu.: 0.000 3rd Qu.:42.27 3rd Qu.: 2.1053 3rd Qu.: 852.0
Max. :820.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-32 Min. :-75.0 Min. : 0.000 Min. :0
1st Qu.: 90.0 1st Qu.:208 1st Qu.:145.0 1st Qu.: 0.000 1st Qu.:0
Median :179.0 Median :234 Median :172.0 Median : 0.000 Median :0
Mean :180.8 Mean :229 Mean :164.4 Mean : 4.615 Mean :0
3rd Qu.:272.0 3rd Qu.:262 3rd Qu.:201.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :429 Max. :322.0 Max. :361.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.38 Mean :-16.06 Mean : 384.6
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-116 Min. :-240.00 Min. : 0.00 Min. :0
1st Qu.: 91.0 1st Qu.: 150 1st Qu.: 50.00 1st Qu.: 0.00 1st Qu.:0
Median :183.0 Median : 204 Median : 100.00 Median : 0.00 Median :0
Mean :182.7 Mean : 208 Mean : 98.87 Mean : 16.25 Mean :0
3rd Qu.:274.0 3rd Qu.: 268 3rd Qu.: 150.00 3rd Qu.: 2.00 3rd Qu.:0
Max. :366.0 Max. : 469 Max. : 332.00 Max. :633.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.85 1st Qu.: -4.488 1st Qu.: 52.0
Median : 0.0000 Median :41.31 Median : -1.293 Median : 261.0
Mean : 0.1054 Mean :40.77 Mean : -1.666 Mean : 376.8
3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 1.331 3rd Qu.: 656.0
Max. :1240.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.00 Min. :-252.00 Min. : 0.00
1st Qu.: 93.0 1st Qu.: 26.00 1st Qu.: -35.00 1st Qu.: 0.00
Median :186.0 Median : 80.00 Median : 13.00 Median : 0.00
Mean :185.3 Mean : 82.05 Mean : 11.88 Mean : 22.03
3rd Qu.:278.0 3rd Qu.: 141.00 3rd Qu.: 64.00 3rd Qu.: 17.00
Max. :366.0 Max. : 277.00 Max. : 188.00 Max. :343.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :40.35 Min. :-4.6800
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.586 Mean :42.25 Mean : 0.7616
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1199.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 890
1st Qu.:1971
Median :2230
Mean :2159
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :-63.0 Min. :-133.00 Min. : 622.0 Min. :0
1st Qu.:110.0 1st Qu.:106.0 1st Qu.: 55.00 1st Qu.: 683.0 1st Qu.:0
Median :272.0 Median :148.0 Median : 102.00 Median : 776.0 Median :0
Mean :219.1 Mean :146.1 Mean : 92.28 Mean : 859.2 Mean :0
3rd Qu.:306.5 3rd Qu.:195.0 3rd Qu.: 138.00 3rd Qu.: 934.5 3rd Qu.:0
Max. :362.0 Max. :332.0 Max. : 240.00 Max. :3361.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -1.9623 1st Qu.: 44.0
Median : 0.000 Median :41.57 Median : 0.8856 Median : 247.0
Mean : 2.595 Mean :40.75 Mean : -0.7467 Mean : 587.5
3rd Qu.: 0.000 3rd Qu.:42.27 3rd Qu.: 2.1053 3rd Qu.: 852.0
Max. :820.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-32 Min. :-75.0 Min. : 0.000 Min. :0
1st Qu.: 90.0 1st Qu.:208 1st Qu.:145.0 1st Qu.: 0.000 1st Qu.:0
Median :179.0 Median :234 Median :172.0 Median : 0.000 Median :0
Mean :180.8 Mean :229 Mean :164.4 Mean : 4.615 Mean :0
3rd Qu.:272.0 3rd Qu.:262 3rd Qu.:201.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :429 Max. :322.0 Max. :361.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.38 Mean :-16.06 Mean : 384.6
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-65.0 Min. :-240.00 Min. : 0.00 Min. :0
1st Qu.: 91.0 1st Qu.:150.0 1st Qu.: 50.00 1st Qu.: 0.00 1st Qu.:0
Median :183.0 Median :204.0 Median : 100.00 Median : 0.00 Median :0
Mean :182.5 Mean :208.6 Mean : 99.03 Mean : 12.39 Mean :0
3rd Qu.:273.0 3rd Qu.:268.0 3rd Qu.: 150.00 3rd Qu.: 1.00 3rd Qu.:0
Max. :366.0 Max. :469.0 Max. : 332.00 Max. :297.00 Max. :0
prof_nieve longitud latitud altitud
Min. :0.00e+00 Min. :28.95 Min. :-13.600 Min. : 1.0
1st Qu.:0.00e+00 1st Qu.:39.85 1st Qu.: -4.488 1st Qu.: 52.0
Median :0.00e+00 Median :41.31 Median : -1.293 Median : 261.0
Mean :7.28e-02 Mean :40.76 Mean : -1.668 Mean : 374.4
3rd Qu.:0.00e+00 3rd Qu.:42.12 3rd Qu.: 1.331 3rd Qu.: 639.0
Max. :1.24e+03 Max. :43.57 Max. : 4.216 Max. :2451.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.00 Min. :-252.00 Min. : 0.00
1st Qu.: 93.0 1st Qu.: 26.00 1st Qu.: -35.00 1st Qu.: 0.00
Median :186.0 Median : 80.00 Median : 13.00 Median : 0.00
Mean :185.3 Mean : 82.05 Mean : 11.88 Mean : 22.03
3rd Qu.:278.0 3rd Qu.: 141.00 3rd Qu.: 64.00 3rd Qu.: 17.00
Max. :366.0 Max. : 277.00 Max. : 188.00 Max. :343.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :40.35 Min. :-4.6800
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.586 Mean :42.25 Mean : 0.7616
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1199.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 890
1st Qu.:1971
Median :2230
Mean :2159
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-116.0 Min. :-143.00 Min. :259.0 Min. :0
1st Qu.: 95.0 1st Qu.: 102.0 1st Qu.: 48.00 1st Qu.:318.0 1st Qu.:0
Median :221.0 Median : 145.0 Median : 90.00 Median :367.0 Median :0
Mean :199.2 Mean : 145.6 Mean : 83.22 Mean :389.2 Mean :0
3rd Qu.:304.0 3rd Qu.: 191.0 3rd Qu.: 126.00 3rd Qu.:442.0 3rd Qu.:0
Max. :366.0 Max. : 369.0 Max. : 254.00 Max. :633.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -4.010 1st Qu.: 69.0
Median : 0.000 Median :41.98 Median : 0.595 Median : 316.0
Mean : 3.257 Mean :41.21 Mean : -1.484 Mean : 611.6
3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.778 3rd Qu.: 852.0
Max. :899.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :-63.0 Min. :-133.00 Min. : 622.0 Min. :0
1st Qu.:110.0 1st Qu.:106.0 1st Qu.: 55.00 1st Qu.: 683.0 1st Qu.:0
Median :272.0 Median :148.0 Median : 102.00 Median : 776.0 Median :0
Mean :219.1 Mean :146.1 Mean : 92.28 Mean : 859.2 Mean :0
3rd Qu.:306.5 3rd Qu.:195.0 3rd Qu.: 138.00 3rd Qu.: 934.5 3rd Qu.:0
Max. :362.0 Max. :332.0 Max. : 240.00 Max. :3361.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -1.9623 1st Qu.: 44.0
Median : 0.000 Median :41.57 Median : 0.8856 Median : 247.0
Mean : 2.595 Mean :40.75 Mean : -0.7467 Mean : 587.5
3rd Qu.: 0.000 3rd Qu.:42.27 3rd Qu.: 2.1053 3rd Qu.: 852.0
Max. :820.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-32 Min. :-75.0 Min. : 0.000 Min. :0
1st Qu.: 90.0 1st Qu.:208 1st Qu.:145.0 1st Qu.: 0.000 1st Qu.:0
Median :179.0 Median :234 Median :172.0 Median : 0.000 Median :0
Mean :180.8 Mean :229 Mean :164.4 Mean : 4.615 Mean :0
3rd Qu.:272.0 3rd Qu.:262 3rd Qu.:201.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :429 Max. :322.0 Max. :361.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.38 Mean :-16.06 Mean : 384.6
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-44.0 Min. :-185.00 Min. : 0.00
1st Qu.: 40.00 1st Qu.:131.0 1st Qu.: 30.00 1st Qu.: 0.00
Median : 79.00 Median :169.0 Median : 67.00 Median : 0.00
Mean : 84.96 Mean :168.8 Mean : 64.56 Mean : 21.18
3rd Qu.:119.00 3rd Qu.:208.0 3rd Qu.: 102.00 3rd Qu.: 9.00
Max. :366.00 Max. :379.0 Max. : 253.00 Max. :297.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :28.95 Min. :-13.600
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.95 1st Qu.: -4.127
Median :0 Median : 0.0000 Median :41.34 Median : -1.229
Mean :0 Mean : 0.1304 Mean :40.83 Mean : -1.572
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 1.363
Max. :0 Max. :1209.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 53.0
Median : 261.0
Mean : 377.9
3rd Qu.: 656.0
Max. :2451.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.00 Min. :-252.00 Min. : 0.00
1st Qu.: 93.0 1st Qu.: 26.00 1st Qu.: -35.00 1st Qu.: 0.00
Median :186.0 Median : 80.00 Median : 13.00 Median : 0.00
Mean :185.3 Mean : 82.05 Mean : 11.88 Mean : 22.03
3rd Qu.:278.0 3rd Qu.: 141.00 3rd Qu.: 64.00 3rd Qu.: 17.00
Max. :366.0 Max. : 277.00 Max. : 188.00 Max. :343.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :40.35 Min. :-4.6800
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.586 Mean :42.25 Mean : 0.7616
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1199.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 890
1st Qu.:1971
Median :2230
Mean :2159
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 58.0 Min. :-65.0 Min. :-240.0 Min. : 0.00 Min. :0
1st Qu.:205.0 1st Qu.:181.0 1st Qu.: 82.0 1st Qu.: 0.00 1st Qu.:0
Median :257.0 Median :250.0 Median : 135.0 Median : 0.00 Median :0
Mean :257.1 Mean :239.1 Mean : 125.4 Mean : 5.67 Mean :0
3rd Qu.:312.0 3rd Qu.:300.0 3rd Qu.: 176.0 3rd Qu.: 0.00 3rd Qu.:0
Max. :366.0 Max. :469.0 Max. : 332.0 Max. :222.00 Max. :0
prof_nieve longitud latitud altitud
Min. :0.00e+00 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.:0.00e+00 1st Qu.:39.49 1st Qu.:-4.488 1st Qu.: 52.0
Median :0.00e+00 Median :41.29 Median :-1.411 Median : 258.0
Mean :2.88e-02 Mean :40.71 Mean :-1.742 Mean : 371.6
3rd Qu.:0.00e+00 3rd Qu.:42.11 3rd Qu.: 1.201 3rd Qu.: 639.0
Max. :1.24e+03 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-116.0 Min. :-143.00 Min. :259.0 Min. :0
1st Qu.: 95.0 1st Qu.: 102.0 1st Qu.: 48.00 1st Qu.:318.0 1st Qu.:0
Median :221.0 Median : 145.0 Median : 90.00 Median :367.0 Median :0
Mean :199.2 Mean : 145.6 Mean : 83.22 Mean :389.2 Mean :0
3rd Qu.:304.0 3rd Qu.: 191.0 3rd Qu.: 126.00 3rd Qu.:442.0 3rd Qu.:0
Max. :366.0 Max. : 369.0 Max. : 254.00 Max. :633.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -4.010 1st Qu.: 69.0
Median : 0.000 Median :41.98 Median : 0.595 Median : 316.0
Mean : 3.257 Mean :41.21 Mean : -1.484 Mean : 611.6
3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.778 3rd Qu.: 852.0
Max. :899.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :-63.0 Min. :-133.00 Min. : 622.0 Min. :0
1st Qu.:110.0 1st Qu.:106.0 1st Qu.: 55.00 1st Qu.: 683.0 1st Qu.:0
Median :272.0 Median :148.0 Median : 102.00 Median : 776.0 Median :0
Mean :219.1 Mean :146.1 Mean : 92.28 Mean : 859.2 Mean :0
3rd Qu.:306.5 3rd Qu.:195.0 3rd Qu.: 138.00 3rd Qu.: 934.5 3rd Qu.:0
Max. :362.0 Max. :332.0 Max. : 240.00 Max. :3361.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -1.9623 1st Qu.: 44.0
Median : 0.000 Median :41.57 Median : 0.8856 Median : 247.0
Mean : 2.595 Mean :40.75 Mean : -0.7467 Mean : 587.5
3rd Qu.: 0.000 3rd Qu.:42.27 3rd Qu.: 2.1053 3rd Qu.: 852.0
Max. :820.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-32.0 Min. :-75.00 Min. : 0.000 Min. :0
1st Qu.: 91.0 1st Qu.:100.0 1st Qu.: 27.00 1st Qu.: 0.000 1st Qu.:0
Median :180.0 Median :143.0 Median : 65.00 Median : 0.000 Median :0
Mean :181.2 Mean :144.6 Mean : 68.22 Mean : 6.009 Mean :0
3rd Qu.:271.0 3rd Qu.:191.0 3rd Qu.:109.00 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :290.0 Max. :206.00 Max. :361.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.:0 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median :0 Median :28.31 Median :-16.5 Median :2371
Mean :0 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.:0 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :0 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-44.0 Min. :-185.00 Min. : 0.00
1st Qu.: 40.00 1st Qu.:131.0 1st Qu.: 30.00 1st Qu.: 0.00
Median : 79.00 Median :169.0 Median : 67.00 Median : 0.00
Mean : 84.96 Mean :168.8 Mean : 64.56 Mean : 21.18
3rd Qu.:119.00 3rd Qu.:208.0 3rd Qu.: 102.00 3rd Qu.: 9.00
Max. :366.00 Max. :379.0 Max. : 253.00 Max. :297.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :28.95 Min. :-13.600
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.95 1st Qu.: -4.127
Median :0 Median : 0.0000 Median :41.34 Median : -1.229
Mean :0 Mean : 0.1304 Mean :40.83 Mean : -1.572
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 1.363
Max. :0 Max. :1209.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 53.0
Median : 261.0
Mean : 377.9
3rd Qu.: 656.0
Max. :2451.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.00 Min. :-252.00 Min. : 0.00
1st Qu.: 93.0 1st Qu.: 26.00 1st Qu.: -35.00 1st Qu.: 0.00
Median :186.0 Median : 80.00 Median : 13.00 Median : 0.00
Mean :185.3 Mean : 82.05 Mean : 11.88 Mean : 22.03
3rd Qu.:278.0 3rd Qu.: 141.00 3rd Qu.: 64.00 3rd Qu.: 17.00
Max. :366.0 Max. : 277.00 Max. : 188.00 Max. :343.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :40.35 Min. :-4.6800
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.586 Mean :42.25 Mean : 0.7616
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1199.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 890
1st Qu.:1971
Median :2230
Mean :2159
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :107.0 Min. : 38.0 Min. : 0.000 Min. :0
1st Qu.: 90.0 1st Qu.:216.0 1st Qu.:156.0 1st Qu.: 0.000 1st Qu.:0
Median :179.0 Median :239.0 Median :178.0 Median : 0.000 Median :0
Mean :180.8 Mean :240.5 Mean :177.5 Mean : 4.426 Mean :0
3rd Qu.:272.0 3rd Qu.:265.0 3rd Qu.:205.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :429.0 Max. :322.0 Max. :336.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-17.75 1st Qu.: 25.0
Median :0 Median :28.46 Median :-16.33 Median : 33.0
Mean :0 Mean :28.38 Mean :-16.00 Mean :114.9
3rd Qu.:0 3rd Qu.:28.63 3rd Qu.:-13.86 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :189.0 Min. :-65.0 Min. :-240.00 Min. : 0.00 Min. :0
1st Qu.:311.0 1st Qu.:117.0 1st Qu.: 19.00 1st Qu.: 0.00 1st Qu.:0
Median :331.0 Median :151.0 Median : 54.00 Median : 0.00 Median :0
Mean :327.9 Mean :148.2 Mean : 51.72 Mean : 9.32 Mean :0
3rd Qu.:349.0 3rd Qu.:180.0 3rd Qu.: 85.00 3rd Qu.: 2.00 3rd Qu.:0
Max. :366.0 Max. :320.0 Max. : 204.00 Max. :222.00 Max. :0
prof_nieve longitud latitud altitud
Min. :0.00e+00 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.:0.00e+00 1st Qu.:40.07 1st Qu.:-4.767 1st Qu.: 79.0
Median :0.00e+00 Median :41.38 Median :-1.885 Median : 370.0
Mean :8.15e-02 Mean :40.80 Mean :-1.938 Mean : 423.1
3rd Qu.:0.00e+00 3rd Qu.:42.18 3rd Qu.: 1.168 3rd Qu.: 687.0
Max. :1.24e+03 Max. :43.57 Max. : 4.216 Max. :1572.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 58.0 Min. :138.0 Min. :-16.0 Min. : 0.000 Min. :0
1st Qu.:188.0 1st Qu.:247.0 1st Qu.:131.0 1st Qu.: 0.000 1st Qu.:0
Median :223.0 Median :283.0 Median :161.0 Median : 0.000 Median :0
Mean :223.7 Mean :281.9 Mean :160.1 Mean : 3.951 Mean :0
3rd Qu.:259.0 3rd Qu.:315.0 3rd Qu.:190.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :365.0 Max. :469.0 Max. :332.0 Max. :180.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.000 1st Qu.:39.49 1st Qu.:-4.127 1st Qu.: 43.3
Median : 0.000 Median :41.19 Median :-1.229 Median : 192.0
Mean : 0.004 Mean :40.66 Mean :-1.650 Mean : 347.4
3rd Qu.: 0.000 3rd Qu.:42.08 3rd Qu.: 1.331 3rd Qu.: 617.0
Max. :1039.000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-116.0 Min. :-143.00 Min. :259.0 Min. :0
1st Qu.: 95.0 1st Qu.: 102.0 1st Qu.: 48.00 1st Qu.:318.0 1st Qu.:0
Median :221.0 Median : 145.0 Median : 90.00 Median :367.0 Median :0
Mean :199.2 Mean : 145.6 Mean : 83.22 Mean :389.2 Mean :0
3rd Qu.:304.0 3rd Qu.: 191.0 3rd Qu.: 126.00 3rd Qu.:442.0 3rd Qu.:0
Max. :366.0 Max. : 369.0 Max. : 254.00 Max. :633.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -4.010 1st Qu.: 69.0
Median : 0.000 Median :41.98 Median : 0.595 Median : 316.0
Mean : 3.257 Mean :41.21 Mean : -1.484 Mean : 611.6
3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.778 3rd Qu.: 852.0
Max. :899.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :-63.0 Min. :-133.00 Min. : 622.0 Min. :0
1st Qu.:110.0 1st Qu.:106.0 1st Qu.: 55.00 1st Qu.: 683.0 1st Qu.:0
Median :272.0 Median :148.0 Median : 102.00 Median : 776.0 Median :0
Mean :219.1 Mean :146.1 Mean : 92.28 Mean : 859.2 Mean :0
3rd Qu.:306.5 3rd Qu.:195.0 3rd Qu.: 138.00 3rd Qu.: 934.5 3rd Qu.:0
Max. :362.0 Max. :332.0 Max. : 240.00 Max. :3361.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -1.9623 1st Qu.: 44.0
Median : 0.000 Median :41.57 Median : 0.8856 Median : 247.0
Mean : 2.595 Mean :40.75 Mean : -0.7467 Mean : 587.5
3rd Qu.: 0.000 3rd Qu.:42.27 3rd Qu.: 2.1053 3rd Qu.: 852.0
Max. :820.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-32.0 Min. :-75.00 Min. : 0.000 Min. :0
1st Qu.: 91.0 1st Qu.:100.0 1st Qu.: 27.00 1st Qu.: 0.000 1st Qu.:0
Median :180.0 Median :143.0 Median : 65.00 Median : 0.000 Median :0
Mean :181.2 Mean :144.6 Mean : 68.22 Mean : 6.009 Mean :0
3rd Qu.:271.0 3rd Qu.:191.0 3rd Qu.:109.00 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :290.0 Max. :206.00 Max. :361.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.:0 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median :0 Median :28.31 Median :-16.5 Median :2371
Mean :0 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.:0 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :0 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. : 37.0 Min. :-68.00 Min. : 0.000
1st Qu.: 53.00 1st Qu.:159.0 1st Qu.: 56.00 1st Qu.: 0.000
Median : 92.00 Median :188.0 Median : 82.00 Median : 0.000
Mean : 88.38 Mean :190.7 Mean : 82.77 Mean : 8.108
3rd Qu.:124.00 3rd Qu.:222.0 3rd Qu.:110.00 3rd Qu.: 2.000
Max. :234.00 Max. :357.0 Max. :205.00 Max. :154.000
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :35.28 Min. :-8.624
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:39.01 1st Qu.:-4.680
Median :0 Median : 0.0000 Median :41.19 Median :-1.008
Mean :0 Mean : 0.0328 Mean :40.58 Mean :-1.543
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.07 3rd Qu.: 1.384
Max. :0 Max. :1209.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 33.0
Median : 108.0
Mean : 261.7
3rd Qu.: 442.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-44.0 Min. :-185.000 Min. : 0.000
1st Qu.: 20.00 1st Qu.: 84.0 1st Qu.: -18.000 1st Qu.: 0.000
Median : 41.00 Median :110.0 Median : 5.000 Median : 0.000
Mean : 45.43 Mean :108.2 Mean : 4.102 Mean : 9.661
3rd Qu.: 65.00 3rd Qu.:135.0 3rd Qu.: 28.000 3rd Qu.: 4.000
Max. :194.00 Max. :239.0 Max. : 106.000 Max. :194.000
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :35.89 Min. :-8.624
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:40.70 1st Qu.:-3.789
Median :0 Median : 0.0000 Median :41.60 Median :-1.650
Mean :0 Mean : 0.3771 Mean :41.33 Mean :-1.482
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 1.296
Max. :0 Max. :1021.0000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 515.0
Median : 690.0
Mean : 698.5
3rd Qu.: 900.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-196.00 Min. :-252.00 Min. : 0.00
1st Qu.: 93.0 1st Qu.: 26.00 1st Qu.: -35.00 1st Qu.: 0.00
Median :186.0 Median : 80.00 Median : 13.00 Median : 0.00
Mean :185.3 Mean : 82.05 Mean : 11.88 Mean : 22.03
3rd Qu.:278.0 3rd Qu.: 141.00 3rd Qu.: 64.00 3rd Qu.: 17.00
Max. :366.0 Max. : 277.00 Max. : 188.00 Max. :343.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :40.35 Min. :-4.6800
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.586 Mean :42.25 Mean : 0.7616
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1199.000 Max. :42.77 Max. : 2.4378
altitud
Min. : 890
1st Qu.:1971
Median :2230
Mean :2159
3rd Qu.:2400
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :107.0 Min. : 38.0 Min. : 0.000 Min. :0
1st Qu.: 90.0 1st Qu.:216.0 1st Qu.:156.0 1st Qu.: 0.000 1st Qu.:0
Median :179.0 Median :239.0 Median :178.0 Median : 0.000 Median :0
Mean :180.8 Mean :240.5 Mean :177.5 Mean : 4.426 Mean :0
3rd Qu.:272.0 3rd Qu.:265.0 3rd Qu.:205.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :366.0 Max. :429.0 Max. :322.0 Max. :336.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-17.75 1st Qu.: 25.0
Median :0 Median :28.46 Median :-16.33 Median : 33.0
Mean :0 Mean :28.38 Mean :-16.00 Mean :114.9
3rd Qu.:0 3rd Qu.:28.63 3rd Qu.:-13.86 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. :189.0 Min. :-65.0 Min. :-240.00 Min. : 0.00 Min. :0
1st Qu.:311.0 1st Qu.:117.0 1st Qu.: 19.00 1st Qu.: 0.00 1st Qu.:0
Median :331.0 Median :151.0 Median : 54.00 Median : 0.00 Median :0
Mean :327.9 Mean :148.2 Mean : 51.72 Mean : 9.32 Mean :0
3rd Qu.:349.0 3rd Qu.:180.0 3rd Qu.: 85.00 3rd Qu.: 2.00 3rd Qu.:0
Max. :366.0 Max. :320.0 Max. : 204.00 Max. :222.00 Max. :0
prof_nieve longitud latitud altitud
Min. :0.00e+00 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.:0.00e+00 1st Qu.:40.07 1st Qu.:-4.767 1st Qu.: 79.0
Median :0.00e+00 Median :41.38 Median :-1.885 Median : 370.0
Mean :8.15e-02 Mean :40.80 Mean :-1.938 Mean : 423.1
3rd Qu.:0.00e+00 3rd Qu.:42.18 3rd Qu.: 1.168 3rd Qu.: 687.0
Max. :1.24e+03 Max. :43.57 Max. : 4.216 Max. :1572.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 58.0 Min. :138.0 Min. :-16.0 Min. : 0.000 Min. :0
1st Qu.:188.0 1st Qu.:247.0 1st Qu.:131.0 1st Qu.: 0.000 1st Qu.:0
Median :223.0 Median :283.0 Median :161.0 Median : 0.000 Median :0
Mean :223.7 Mean :281.9 Mean :160.1 Mean : 3.951 Mean :0
3rd Qu.:259.0 3rd Qu.:315.0 3rd Qu.:190.0 3rd Qu.: 0.000 3rd Qu.:0
Max. :365.0 Max. :469.0 Max. :332.0 Max. :180.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.000 1st Qu.:39.49 1st Qu.:-4.127 1st Qu.: 43.3
Median : 0.000 Median :41.19 Median :-1.229 Median : 192.0
Mean : 0.004 Mean :40.66 Mean :-1.650 Mean : 347.4
3rd Qu.: 0.000 3rd Qu.:42.08 3rd Qu.: 1.331 3rd Qu.: 617.0
Max. :1039.000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-116.0 Min. :-143.00 Min. :259.0 Min. :0
1st Qu.: 95.0 1st Qu.: 102.0 1st Qu.: 48.00 1st Qu.:318.0 1st Qu.:0
Median :221.0 Median : 145.0 Median : 90.00 Median :367.0 Median :0
Mean :199.2 Mean : 145.6 Mean : 83.22 Mean :389.2 Mean :0
3rd Qu.:304.0 3rd Qu.: 191.0 3rd Qu.: 126.00 3rd Qu.:442.0 3rd Qu.:0
Max. :366.0 Max. : 369.0 Max. : 254.00 Max. :633.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.87 1st Qu.: -4.010 1st Qu.: 69.0
Median : 0.000 Median :41.98 Median : 0.595 Median : 316.0
Mean : 3.257 Mean :41.21 Mean : -1.484 Mean : 611.6
3rd Qu.: 0.000 3rd Qu.:42.47 3rd Qu.: 1.778 3rd Qu.: 852.0
Max. :899.000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. : 3.0 Min. :-63.0 Min. :-133.00 Min. : 622.0 Min. :0
1st Qu.:110.0 1st Qu.:106.0 1st Qu.: 55.00 1st Qu.: 683.0 1st Qu.:0
Median :272.0 Median :148.0 Median : 102.00 Median : 776.0 Median :0
Mean :219.1 Mean :146.1 Mean : 92.28 Mean : 859.2 Mean :0
3rd Qu.:306.5 3rd Qu.:195.0 3rd Qu.: 138.00 3rd Qu.: 934.5 3rd Qu.:0
Max. :362.0 Max. :332.0 Max. : 240.00 Max. :3361.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.: -1.9623 1st Qu.: 44.0
Median : 0.000 Median :41.57 Median : 0.8856 Median : 247.0
Mean : 2.595 Mean :40.75 Mean : -0.7467 Mean : 587.5
3rd Qu.: 0.000 3rd Qu.:42.27 3rd Qu.: 2.1053 3rd Qu.: 852.0
Max. :820.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. : -9.0 Min. :-63.00 Min. : 76.0 Min. :0
1st Qu.: 96.0 1st Qu.:128.0 1st Qu.: 67.00 1st Qu.:138.0 1st Qu.:0
Median :159.0 Median :163.0 Median : 97.00 Median :169.0 Median :0
Mean :182.8 Mean :168.8 Mean : 96.95 Mean :176.5 Mean :0
3rd Qu.:287.0 3rd Qu.:205.0 3rd Qu.:128.00 3rd Qu.:212.0 3rd Qu.:0
Max. :366.0 Max. :379.0 Max. :253.00 Max. :297.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.95 Min. :-13.600 Min. : 1
1st Qu.: 0.0000 1st Qu.:40.80 1st Qu.: -5.498 1st Qu.: 61
Median : 0.0000 Median :41.88 Median : -2.039 Median : 261
Mean : 0.2077 Mean :41.43 Mean : -2.120 Mean : 384
3rd Qu.: 0.0000 3rd Qu.:42.70 3rd Qu.: 1.363 3rd Qu.: 617
Max. :1001.0000 Max. :43.57 Max. : 4.216 Max. :2451
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)